package com.ziven.learn.main;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ziven.easygo.design.mvp.OneData;
import com.ziven.easygo.design.mvp.OneModel;
import com.ziven.easygo.util.DataProvider;
import com.ziven.easygo.util.EasyUtils;
import com.ziven.easygo.util.LogHelper;
import com.ziven.processor.LearnBaseBean;
import com.ziven.processor.LearnCreate;
import com.ziven.processor.LearnFactory;

import java.util.List;
import java.util.Map;

/**
 * @author Ziven
 */
public class MainModel extends OneModel {

    @Override
    protected void obtainOneData(@Nullable Context c, @Nullable Map<Object, Object> params) {
        LogHelper.of().always().join("obtainOneData").print();
        obtainedOneData(OneData.of(DataProvider.of(getList(c)).addList(getList()).getList()));
    }

    @NonNull
    private List<LearnBaseBean> getList(@Nullable Context context) {
        return context instanceof LearnCreate
                ? EasyUtils.newIfNull(((LearnCreate) context).create(), EasyUtils::newList)
                : EasyUtils.newList();
    }

    @NonNull
    private List<LearnBaseBean> getList() {
        return EasyUtils.newIfNull(new LearnFactory().create(), EasyUtils::newList);
    }
}
